export default {
  // components:{
  //   ElTreeGrid.name:
  // }
  data () {
    return {
      cateList: [],
      pagenum: 1,
      total: 0,
      // 进入页面不展示对话框
      isShowAddCateDialog: false,
      // 添加分类对话框数据
      cateForm: {
        cat_name: '',
        cat_pid_arr: []
      },
      addCateForm: []

    }
  },
  created () {
    this.getCateList()
    this.getAddCateList()
  },
  methods: {
    // 获取数据，渲染页面
    async getCateList (pagenum = 1) {
      const res = await this.$http.get('/categories', {
        params: {
          type: 3,
          pagenum,
          pagesize: 5
        }
      })
      const { result, total, pagenum: curPage } = res.data.data
      // console.log(res.data.data)
      this.pagenum = curPage
      this.cateList = result
      this.total = total
    },
    showAddCateDialog () {
      this.isShowAddCateDialog = true
    },
    currentChange (curPage) {
      this.getCateList(curPage)
    },
    async getAddCateList () {
      const res = await this.$http.get('/categories', {
        params: {
          type: 2
        }
      })
      console.log(res.data)
      this.addCateForm = res.data.data
    },
    async addCate () {
      /* eslint-disable */
      const {cat_name, cat_pid_arr} = this.cateForm
      const res = await this.$http.post('/categories', {
        cat_pid:cat_pid_arr[cat_pid_arr.length-1],
        cat_name,
        cat_level:cat_pid_arr.length
      })
      console.log(res)     
      // 创建成功
      // this.cateForm=''
      this.isShowAddCateDialog = false
      this.getCateList()
      this.$message({
        type:'success',
        message:res.data.meta.msg
      })
    }
  }
}
